<template>
  <div>
    <ul class="todo-main">
      <TodoItem v-for="(value,index) in todos" :key="index" :todo="value" :index="index"/>
    </ul>
  </div>
</template>

<script>
import TodoItem from "./TodoItem";
import {mapState} from 'vuex'
import storageUtils from "../util/storageUtils";

export default {
  name: "TodoList",
  // 从state中读取数据在computed中进行
  computed: {
    ...mapState(['todos'])
  },
  watch: {
    todos: {
      deep: true,
      handler: storageUtils.saveTodos
    }
  },
  components: {
    TodoItem
  }
}
</script>

<style scoped>

/*main*/
.todo-main {
  margin-left: 0px;
  border: 1px solid #ddd;
  border-radius: 2px;
  padding: 0px;
}

.todo-empty {
  height: 40px;
  line-height: 40px;
  border: 1px solid #ddd;
  border-radius: 2px;
  padding-left: 5px;
  margin-top: 10px;
}

</style>
